using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SajtLibrary.SajtClasses;

/// <summary>
/// Summary description for SessionUtils
/// </summary>
public class SessionUtils
{
    public SessionUtils()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static bool isCurrentUserAnnonimous() 
    {
        return (HttpContext.Current.Session["user"] == null);
    }

    public static void storeUserInformation(User user)
    {
        if (!(HttpContext.Current.Session["user"] == null))
        {
            HttpContext.Current.Session.Add("user", user);
            //throw new Exception("User is already present in Session");
        }
    }

    public static void removeUserInformation()
    {
        HttpContext.Current.Session.Remove("user");
    }

    public static bool isCurrentUserAdmin()
    {
        User curruser = getCurrentUser();
        return curruser != null && curruser.IsAdministrator;
    }

    public static bool isCurrentUserClient()
    {
        User curruser = getCurrentUser();
        return curruser != null && curruser.IsClient;
    }

    public static User getCurrentUser()
    {
        return (User)HttpContext.Current.Session["user"];
    }
}
